import os
import json

from kitool.Md5Kit import calculate_md5

from kitool.DateKit import get_datestr


def data_list(directory, name):
    md5_list = []
    result_list = []

    nowstr = get_datestr()

    full_path = os.path.join(directory, nowstr, nowstr + '__' + name + '.json')
    with open(full_path, 'r', encoding='UTF-8') as file:
        content = file.read()
        data_list = json.loads(content)
        for item in data_list:
            md5 = calculate_md5(item['chief_complaint'][:9])
            if md5 not in md5_list:
                md5_list.append(md5)
                result_list.append(item)

    # return
    return result_list